feat(#1549): copy files between multiple nvim instances#3336
Conversation
There was a problem hiding this comment.
This is looking great, only minor changes required.
Please:
- handle spaces etc. in register as per
gptest case, moving to a newline delimited format as per "standard" with newlines between files, but not after the last file - move
Node:get_basenametoClipboard
Test cases:
gy
- copy one
/home/alex/src/linux/.mailmap - visual copy
/home/alex/src/linux/.pylintrc,/home/alex/src/linux/.rustfmt.toml - copy root
/home/alex/src/linux/ -
visual copy root and other nodes
root is not copied, however that's OK. This is existing behaviour and arguably a feature, as copying root and other files makes no sense.
ge
- copy one
.mailmap - visual copy
.pylintrc,.rustfmt - copy root
linux -
visual copy root and other nodes, ok, see above
gp
- paste one
/home/alex/src/linux/MAINTAINERS - paste many
/home/alex/src/linux/COPYING,/home/alex/src/linux/CREDITS - FAIL - paste with spaces
/home/alex/src/linux/CREDITS, /home/alex/src/linux/Kbuild, /home/alex/src/linux/Kconfig
[NvimTree] Could not copy /home/alex/src/linux/CREDITS - ENOENT - paste one inexistent
/home/alex/src/linux/xxx
[NvimTree] Could not copy /home/alex/src/linux/xxx - ENOENT - paste many, one inexistent
/home/alex/src/linux/Kbuild,/home/alex/src/linux/xxx,/home/alex/src/linux/MAINTAINERS
[NvimTree] Could not copy /home/alex/src/linux/xxx - ENOENT
others copied correctly - paste mixed nodes and directories
/home/alex/src/linux/zzz/,/home/alex/src/linux/aaa
gx
- Test cases as per
gp - Multiple source removed when in same instance
/home/alex/src/linux/Kconfig,/home/alex/src/linux/MAINTAINERS - Multiple source removed in other instance in the same directory
/home/alex/src/linux/.clang-format,/home/alex/src/linux/.clippy.toml
| end | ||
|
|
||
| function Node:get_basename() | ||
| if self.name == ".." then |
There was a problem hiding this comment.
On further reflection, changing the ".." makes me nervous. Yes it's legacy, however it is present in many places in Clipboard hence we shouldn't change it when building this feature.
Let's keep it localised - please move this method to Clipboard so that it doesn't spread to other functionality.
That would be great, I have some use cases for it. Out of scope, future PR please :) |
|
Wild and crazy idea after reading comments on previous PR: Remove
|
|
I finally installed the gnome file manager nautilus and inspected the clipboard mime types when copying multiple files: : ; wl-paste --list-types
x-special/gnome-copied-files
text/plain;charset=utf-8
text/uri-list
application/vnd.portal.filetransfer
application/vnd.portal.files
: ; wl-paste --type text/plain\;charset=utf-8
/home/alex/src/linux/.gitattributes
/home/alex/src/linux/.gitignore
/home/alex/src/linux/.mailmap
: ; wl-paste --type text/uri-list
file:///home/alex/src/linux/.gitattributes
file:///home/alex/src/linux/.gitignore
file:///home/alex/src/linux/.mailmap
: ; wl-paste --type application/vnd.portal.filetransfer
10924863569610452011%
: ; wl-paste --type application/vnd.portal.files
11848482484090875390%
: ; wl-paste --type x-special/gnome-copied-files
copy
file:///home/alex/src/linux/.gitattributes
file:///home/alex/src/linux/.gitignore
file:///home/alex/src/linux/.mailmap%
: ;Today I think we should at least match the
For reference, this is what a : ; wl-paste --list-types
text/plain
text/plain;charset=utf-8
TEXT
STRING
UTF8_STRING
: ; wl-paste --type UTF8_STRING
/home/alex/src/linux/Kbuild,/home/alex/src/linux/Kconfig
: ; wl-paste --type TEXT
/home/alex/src/linux/Kbuild,/home/alex/src/linux/Kconfig
: ; wl-paste --type STRING
/home/alex/src/linux/Kbuild,/home/alex/src/linux/Kconfig
: ; wl-paste --type text/plain
/home/alex/src/linux/Kbuild,/home/alex/src/linux/Kconfig
: ; wl-paste --type text/plain\;charset=utf-8
/home/alex/src/linux/Kbuild,/home/alex/src/linux/Kconfig
: ;KDE dolpin operates similarly except that it does not copy |
Makes total sense removing The only thing is that |
That's great. The unique problem usinf this approach is that it will resamble protocol and hence we won't be able to paste from anywhere else by simply grabbing the absolute path and vice-versa maybe. This would suite better if we kept |
Yeah that's a tricky one, there's no "natural" option. I'm easy for any mapping, however we can't do |
Yes, let's just go with newlines for now. This branch is working. We can add a protocol in the future :) |
The protocol will break OS level operation, which I think is one of the biggest win for this. And yes protocol would make this nvim specific but I think it would be cooler to make it work anywhere. Changes To Be Made
Together with those mentioned earlier. |
… work in visual mode
…data or register data
|
All changes made and all test passing. Concern
Additional changes made, mostly refactor
|
We could do both eventually - continue to put the files in the |
I don't think there's much we can do about that, which is kind of an edge case. It does work as described for the base cases, and multiple copies (especially cuts) like this will likely "break" most applications. |
alex-courtis
left a comment
There was a problem hiding this comment.
This is looking fantastic. It feels just right to copy between.
Existing test cases look good, and I can successfully paste from gnome now!!!
Please:
- remove new API if not needed
- revert
copy_node_attributesrefactor - resolve multiple copy test case below
New test cases:
Needs Fixing - Multiple Copy
Directory with files a b c d
Multiple Single Copies
Normal copy a
a marked in green
Clip OK:
/home/alex/src/linux/foo/a
Normal copy b
a and b marked in green
Clip missing a:
/home/alex/src/linux/foo/b
Multiple Visual Copy Toggling
Visual Copy a and b
a and b marked in green
Clip OK:
/home/alex/src/linux/foo/a
/home/alex/src/linux/foo/b
Visual Copy b and c
a and c marked in green
Clip Incorrect:
/home/alex/src/linux/foo/b
/home/alex/src/linux/foo/c
In both cases it looks like we need to put the final contents of clipboard.data into the clipboard, not the visual operation nodes.
| ---Paste nodes from the system register as files to nvim-tree while copying. | ||
| --- | ||
| ---@param node_or_nodes? nvim_tree.api.Node | nvim_tree.api.Node[] | ||
| function nvim_tree.api.fs.paste_from_register_copying(node_or_nodes) end |
There was a problem hiding this comment.
Do we still need these two? They don't appear to be used. p does the job now :)
| ---@field remove_file? nvim_tree.config.actions.remove_file | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
I'm guessing the style tooling fixed this.
| local node_attribute_getters = { | ||
| basename = function(n) return self:get_node_basename(n) end, | ||
| filename = function(n) return self:get_node_filename(n) end, | ||
| relative_path = function(n) return self:get_node_relative_path(n) end, | ||
| absolute_path = function(n) return self:get_node_absolute_path(n) end, | ||
| } |
There was a problem hiding this comment.
I really appreciate the care and effort you've made with this refactor, however:
- it obfuscates the flow of control: it's no longer easy to "LSP References"
get_node_relative_pathto map it directly to API/impl - it's doesn't appear necessary to achieve the goal of copy between instances
Let's limit the scope of this change to the minimum required to achieve the functionality: atomic changes.
- It ensures that we can look at git history and identify what was the new functionality and what was a refactor.
- In the case of a problem it allows us to identify whether the problem was the functionality or the refactor.
- Allows reverting/reapplying of individual changes in the event of an issue, instead of having to revert the larger change
I'm always open to refactors and polishing, however please raise separate PRs for them.
There was a problem hiding this comment.
Thanks for the alert @alex-courtis, should I open a dedicated refactor PR? (I think know from the points you brought).
I just tried to automate to because I was making all of them to support visual mode. Should I simply drop the visual support also, or maybe another PR right away?


Hello @alex-courtis this is simply a variation of what we've been discussing at #3334 I just wanted to show it in practice and is btw the thing that I've been dogfooding, I am thinking in even adding option to download a file directly when an url is on the register (maybe for my own locally if this is too nichy).
Changes
1 -
gy- remains as it is, and now supports visual operation which copies a list of comma separated absolute paths2 -
gp- this is used to paste while copying3 -
gx- this is used to paste while cutting.2026-06-15.00-39-13.mp4